<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<% String path=request.getContextPath(); String basePath=request.getScheme()+ "://" + request.getServerName() + ":" + request.getServerPort() + path+ "/"; %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" >
<html  xmlns="http://www.w3.org/1999/xhtml"> 
<head>
<base href="<%=basePath%>">
<title>激活卡出库</title>
<%@ include file="/WEB-INF/jsp/common/common.jsp" %>
<script src="js/jquery.divbox.js" type="text/javascript"></script>
	<style>
		.input_button_1,
		.input_button_2{
			margin-right: 10px;
		}
		.h_30 {
			height: 30px;
			line-height: 30px;
		}
		.table_body_div {
			padding: 30px;
		}
		.table_body_title {
			font-weight: bold;
			font-size: 16px;
		}
		.fr {
			float: right;
		}
		.fl {
			float: left;
		}
		.depts {
			padding-top: 10px;
		}
		/* 清除浮动 */
		.depts::after {
			clear:both;
			content:'.';
			display:block;
			width: 0;
			height: 0;
			visibility:hidden;
		}/*==for FF/chrome/opera/IE8==*/
		.depts li {
			width: 25%;
			float: left;
			line-height: 30px;
			height: 30px;
		}
		.depts li input {
			margin-right: 5px;
		}
		#areaDiv {
			padding-bottom: 20px;
		}
    .dialogTitle {
        height: 31px;
        line-height: 31px;
        padding-left: 10px;
        color: #333;
        font-weight: bold;
        font-size: 14px;
        text-align:center
    }
	</style>
	<script type="text/javascript">
	/*----------- 初始化 ------------------- */
	function init() {
		queryChannelInfo('1')
	}
	$(function() {
		//添加/编辑成功返回该页面的提示
		<%if(null != request.getAttribute("flag")){
			if("success".equals(request.getAttribute("flag").toString())){
			    if(null != request.getAttribute("pricelessType")){
 			        if("0".equals(request.getAttribute("pricelessType").toString())){%>
				        $.message("success","出库成功!\n请缴费，缴费成功后激活卡才是可激活状态！");
				    <%}else if("1".equals(request.getAttribute("pricelessType").toString())){%>
				        $.message("success","出库成功!\n该批卡单不预收保费，激活卡已是可激活状态！");
				    <%}%>
				<%}else{%>
				    $.message("success","出库成功!\n该批卡单不预收保费，激活卡已是可激活状态！");
				<%}%>			
		    <%}%>
		<%}%>
		init()
	})
	/*----------- 初始化 ------------------- */
	/* 查询卡出库记录*/
	function queryChannelInfo(displayPage){
		var name= $("#name").val();
		loadQueryData({current:displayPage,size:10,name: name});
	}
	function loadQueryData(param){
		var jsonDate;
		if(null != param && null != param.current){
			jsonDate =param;	
		}else{
			jsonDate={current:1,size:10};
		}
		$.openLoading();
		$.ajax({
			url : "outboundCard/queryOutboundList",
			type : 'POST',
			async : true,
			dataType:'json',
			data:jsonDate,
			success : function(page) {
				$.closeLoading();
				if($.validate(page))return;
				$("#row_num").val(page.total);
				var radioObj ="<input class='input_fxk' name='radioCard' type='radio' value='#'>";
				var fieldNames = "name,pricelessType?[{0:'有价'};{1:'非有价'}],deptName,minNo,maxNo,count,totPremAmtStr,status?[{0:'库存'}],docId,cardDefineId@TDH,deptNo@TDH,preFee@TDH,planNo@TDH,pricelessType@TDH,planName@TDH,typeCode@TDH";
				var tableContent = creatTable1(fieldNames, page, radioObj);
				var tableObj = $("#cardInfoTable");
				tableObj.find("tbody").remove();
				tableObj.append(tableContent);
				
				var strPage = creatChannelPage(page.current,6,page.maxPage,"1");
				var pageDIV = $("#txCardpageDIV");
				pageDIV[0].innerHTML="";
				pageDIV.append(strPage);
				bindradio();//点击单选按钮，该行高亮显示
			}
		})
	}
	function bindradio(){
		$("input[name='radioCard']").click(function(){
			$("input[name='radioCard']").parent().parent().removeClass("table_highlighter");
			$("input[name='radioCard']:checked").parent().parent().addClass("table_highlighter");
	   	});
    }
	
	//选择出库申请
	var premAmt;
	function outboundApply(){
		var radioCard = $("input[name='radioCard']:checked");
		if(radioCard.val()!=undefined){
			var flagCardDefineId=10;
			var flagName=1;
			var flagdeptName=3;
            var flagMinNo=4;
			var flagCount=6;
			var flagPreAmt=7;
			var flagdeptNo=11;
			var flagPlanNo=13;
			var flagPricelessType=14;
			var flagPlanName=15;
			var flagTypeCode=16;
			var typeCode = radioCard.parent().parent().children(" td:eq("+flagTypeCode+")").html();
			if(typeCode!='3'){
				$.message("error","激活卡系统目前只支持新意健险激活卡！");
				return;
			}
			var cardDefineId = radioCard.parent().parent().children(" td:eq("+flagCardDefineId+")").html();
			var deptNo = radioCard.parent().parent().children(" td:eq("+flagdeptNo+")").html();
			var deptName = radioCard.parent().parent().children(" td:eq("+flagdeptName+")").html();
			var name = radioCard.parent().parent().children(" td:eq("+flagName+")").html();
			var planNo = radioCard.parent().parent().children(" td:eq("+flagPlanNo+")").html();
			var planName = radioCard.parent().parent().children(" td:eq("+flagPlanName+")").html();
			var minNo = radioCard.parent().parent().children(" td:eq("+flagMinNo+")").html();
			var count = radioCard.parent().parent().children(" td:eq("+flagCount+")").html();
			var pricelessType=radioCard.parent().parent().children(" td:eq("+flagPricelessType+")").html();
			premAmt = radioCard.parent().parent().children(" td:eq("+flagPreAmt+")").html();
	 		$("#cardDefineId").val(cardDefineId);
	 		$("#pricelessType").val(pricelessType);
	 		$("#planNo").val(planNo);
	 		$("#planName").val(planName);
	 		$("#eCount").val('');
			if(planNo!=null&&planNo!=''){
				$.openLoading_jhk();
		        $.ajax({
		            url : "outboundCard/queryCardPlan",
		            type : 'POST',
		            async : true,
		            dataType:'json',
		            data:{planNo:planNo},
		            success : function(result) {
		                $.closeLoading();
		                if($.validate(result))return;
		                /* if("error"==result.result && ""!=result.message){
		                    $.message('error',result.message);
		                }
		                if("fail"==result.result){
		                    $.message("error", "系统错误,请联系管理员");
		                } */
		                var planInfo=result.plan;
		                //if("success"==result.result&&""!=result.message){
		                    if(planInfo!=null){
		                        $("#editOutboundDiv").OpenDiv();
		                        $("#eName").val(name);
		                        $("#eCardNo").val(minNo);
		                        $("#edeptNo").val(deptNo);
		                        $("#edeptName").val(deptName);
		                    }else{
		                        $.message('error','该激活卡还没有配置销售方案,不可以出库！');
		                    }
		                //}
		            }
		        });
			}else{
				$.message("error","此激活卡还没有配置销售方案！");
			}
		}else{
			$.message("error", "请选择一条记录");
		}	
	}
	
	//关闭小窗口
	function closeEditOutboundDiv(){
		$("#editOutboundDiv").CloseDiv();
	}
	
	function saveEditOutbound(){
		var $name = $("#eName");
		var $cardNo = $("#eCardNo");
		var $count = $("#eCount");
		var deptNo=$("#edeptNo").val();
        var deptName=$("#edeptName").val();
		var cardDefineId=$("#cardDefineId").val();
		var pricelessType=$("#pricelessType").val();
		var planNo=$("#planNo").val();
		var planName=$("#planName").val();
	    //卡单起始号
	    if($cardNo.val()==""){
	    	$.message("error","请输入卡单起始号");
	    	$cardNo.focus();
	    	return;
	    }
	    if($.trim($count.val()).length==0){
	    	$.message("error","出库份数不能为空");
	    	$count.focus();
	    	return;
	    }else{
	        if(!(!isNaN($count.val())&&$count.val()>0)){
	        	$.message("error","出库份数必须是大于0的整数")
	        	$count.focus();
	        	return;
	        }
	        var $row_num = $("#row_num");
    		var name = $name.val();
    		var cardNo = $cardNo.val();
    		var count = $count.val();
	        var jsonDate={name:name,cardNo:cardNo,cardDefineId:cardDefineId,deptName:deptName,planName:planName};
	        $.openLoading();
			$.ajax({
				url : "outboundCard/queryCountMax",
				type : 'POST',
				async : true,
				dataType:'json',
				data: jsonDate,
				success : function(result) {
					var countMax=result.data;
					if("error"==result.result&&""!=result.message){
	                    $.closeLoading();
			    		$.message("error", result.message);
			    	}
					if("fail"==result.result){
	                    $.closeLoading();
			    		$.message("error", "系统错误,请联系管理员");
			    	}
					if("success"==result.result&&""!=result.message){
						if(count-100>0){
							if(100-countMax>0){
	                            $.closeLoading();
	                            $.message("error", "从卡号" + cardNo+"开始的" + name + ":剩下"+countMax+"张！");
	                            $count.val(countMax);
	                            return;
							}else{
                                $.closeLoading();
                                $.message("error", "每次出库限制100张！");
                                $count.val(100);
                                return;
							}
						}else if(count-countMax>0){
	                        $.closeLoading();
				        	$.message("error", "从卡号" + cardNo+"开始的" + name + ":剩下"+countMax+"张！");
				        	$count.val(countMax);
				        	return;
				        }else{
				        	//name=encodeURI(name);
				        	//alert(name);
				    	    window.location.href='<%=path%>/outboundCard/outboundApply?cardDefineId='+cardDefineId+'&cardNo='+cardNo+'&count='+count+'&premAmt='+premAmt+'&pricelessType='+pricelessType+'&planNo='+planNo;
				        }
					}
				}
			});
		}
	}
	
	function vreset(){
		$("#name").val("");
	}
	
	//跳转到出库明细查询页面
	function outboundDetail(){
		
		window.location.href='<%=path%>/outboundCard/queryOutboundDetail';
	}
	</script>
</head>
<body >
	<div class="current">
		<table class="current_table_1">
			<tbody>
				<tr class="f2">
		            <td>
		              <img src="./images/current_1.jpg">
		            </td>
		            <td class="current_table_1_td">
		              <img src="images/current_1.png">&nbsp;您现在的位置：&nbsp;
		                <span style=" color:#136bab; ">激活卡管理
		                	<span style="padding:0 5px; font-weight:bold; line-height:28px;">&gt;</span>
		                	激活卡出库
		            	</span>
		            </td>
		            <td><img src="./images/current_3.jpg"></td>
	        	</tr>
			</tbody>
		</table>
	</div>			
		
	<table class="table_02" id="table">
		<tr>
			<td>
				<table class="search_table">
					<tr class="h_30">
						<td width="20%" class="h_30">卡定义名称：
							<input name="txt3" id="name" type="text" class="input_text" maxlength="100" value="">
						</td>
					</tr>
					<tr>
						<td height="30"   colspan="4" style="text-align: center;">
						  <input type="button" class="input_button_1"
							id="searchBtn" value="查询" onClick="queryChannelInfo(1)" /> 
						  <input
							type="button" class="input_button_1" id="searchBtn" value="重置"
							onClick="vreset()" />
						  <input type="button"  class="input_button_2" id="searchBtn" value="出库缴费" onClick="outboundDetail()"/>&nbsp;
						</td>
					</tr>
				</table>
			</td>
		</tr>		
		<tr>
			<td>
				<table class="search_table">
					<tr height="30px">
						<td width="100%" height="30">
							 <input type="button"  class="input_button_2" id="searchBtn" value="出库申请" onClick="outboundApply()"/>&nbsp;
						</td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td>
	  			<div id="cardDiv" style="width:98%" >
					<table id="cardInfoTable" class="content_table_1">
						<thead>
							<tr class="f1">
								<th style="width:5%;">选择</th>
								<th style="width:18%;">卡定义名称</th>
								<th style="width:6%;">卡类型</th>
								<th style="width:21%;">归属机构</th>
								<th style="width:12%;">最小卡号</th>
								<th style="width:12%;">最大卡号</th>
								<th style="width:6%;">数量</th>
								<th style="width:6%;">保费</th>
								<th style="width:7%;">状态</th>
								<th style="width:7%;">单证类型</th>
							</tr>
						</thead>
						<tbody>
						</tbody>
					</table>
					<div id="txCardpageDIV" class="page"></div>
				</div>
			</td>
		</tr>
	</table>
	<!--   	添加模板 DIV 默认隐藏-->
    <div id="editOutboundDiv"  style="display:none;overflow-y:auto; width:60%">
		<input type="hidden" id="row_num" name="row_num" />
		<input type="hidden" id="edeptNo" name="edeptNo" />
        <input type="hidden" id="edeptName" name="edeptName" />
		<input type="hidden" id="cardDefineId" name="cardDefineId" /> 
		<input type="hidden" id="pricelessType" name="pricelessType" /> 
		<input type="hidden" id="planNo" name="planNo" /> 
		<input type="hidden" id="planName" name="planName" /> 
		<div class="table_title_div">
				<table class="table_title" style='width:100%;height: 20px;'>
					<tr>
					<td width="10%"></td>
					<td width="80%" id="interfaceName"></td>
					<td width="10%" align="right"><img src="/manager/images/closedown.gif" alt="关闭"  onclick="closeEditOutboundDiv()"/></td>
					</tr>
				</table>
		</div>
		<div class="dialogTitle">
                                出库申请
        </div>
		<!-- 修改id 名 -->
		<table id="addtempletTable" style="align:center;margin: 10px auto;border:0">
			<tbody>
				<tr>
					<td>
						<table id="coverageTable"  class="content_table_1" border="0" align="center">	
							<tbody>
								<tr style="text-align:center">
				                  <td width="40%" style="text-align:right;border-right:0px;">卡定义名称：&nbsp;</td>
				                  <td width="60%" style="text-align:left"><input id="eName" name="eName" readonly="readonly" style="background-color: #ccc;width: 200px" class="input_text" ></td>
				                </tr>
				                <tr style="text-align:center">  
				                  <td width="40%" style="text-align:right;border-right:0px;">卡单起始号：&nbsp;</td>
				                  <td width="60%" style="text-align:left"><input id="eCardNo" name="eCardNo" style="width: 200px" class="input_text" ></td>
				                </tr>
					            <tr style="text-align:center">  
				                  <td width="40%" style="text-align:right;border-right:0px;">出库份数：&nbsp;</td>
				                  <td nowrap="nowrap" width="60%" style="text-align:left"><input id="eCount" name="eCount" class="input_text" style="width: 200px" onkeyup="this.value=this.value.replace(/\D/g, '')"><span class="red">*</span></td>
				                </tr>
							</tbody>
						</table>
					</td>
				</tr>
			</tbody>
		</table>
		<div align="center">
		   <input class="input_button_3" name="" type="button" onclick="saveEditOutbound()" value="确定">&nbsp;&nbsp;
           <input class="input_button_3" name="" type="button" onclick="closeEditOutboundDiv()" value="取消">
		</div>
	</div>
	
	<div id="Loading" style="display:none" align="center">
		<img src="./images/loading.gif" />
	</div>	
</body>
</html>